<html>
<head>
<title>reeborg</title>
</head>
<body>
reeborg
<style>
.coverage pre {float: left; margin: 0px 1em; border: none;
               padding: 0px; }
.num pre { margin: 0px }
.nocov, .nocov pre {background-color: #faa}
.cov, .cov pre {background-color: #cfc}
div.coverage div { clear: both; height: 1.1em}
</style>
<div class="stats">
Covered: 243 lines<br/>
Missed: 3 lines<br/>
Skipped 35 lines<br/>
Percent: 98 %<br/>

</div>
<div class="coverage">
<div class="skip"><span class="num"><pre>  1</pre></span><pre># -*- coding: utf-8 -*-</pre></div>
<div class="skip"><span class="num"><pre>  2</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>  3</pre></span><pre>import re</pre></div>
<div class="skip"><span class="num"><pre>  4</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>  5</pre></span><pre>_builtins = {</pre></div>
<div class="cov"><span class="num"><pre>  6</pre></span><pre>    &quot;en&quot;: {&quot;move()&quot;: &quot;move&quot;,</pre></div>
<div class="cov"><span class="num"><pre>  7</pre></span><pre>           &quot;turn_left()&quot;: &quot;turn_left&quot;,</pre></div>
<div class="cov"><span class="num"><pre>  8</pre></span><pre>           },</pre></div>
<div class="cov"><span class="num"><pre>  9</pre></span><pre>    &quot;fr&quot;: {&quot;avance()&quot;: &quot;move&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 10</pre></span><pre>           &quot;tourne_a_gauche()&quot;: &quot;turn_left&quot;</pre></div>
<div class="cov"><span class="num"><pre> 11</pre></span><pre>           },</pre></div>
<div class="cov"><span class="num"><pre> 12</pre></span><pre>}</pre></div>
<div class="skip"><span class="num"><pre> 13</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 14</pre></span><pre>_conditions = {</pre></div>
<div class="cov"><span class="num"><pre> 15</pre></span><pre>    &quot;on_beeper()&quot;: &quot;on_beeper()&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 16</pre></span><pre>    &quot;True&quot;: True,</pre></div>
<div class="cov"><span class="num"><pre> 17</pre></span><pre>    &quot;False&quot;: False</pre></div>
<div class="cov"><span class="num"><pre> 18</pre></span><pre>}</pre></div>
<div class="skip"><span class="num"><pre> 19</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 20</pre></span><pre>_messages = {</pre></div>
<div class="cov"><span class="num"><pre> 21</pre></span><pre>    &quot;en&quot;: {&quot;Unknown command&quot;: &quot;Unknown command: %s&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 22</pre></span><pre>           &quot;Indentation error&quot;: &quot;Indentation error&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 23</pre></span><pre>           &quot;Attempt to redefine&quot;: &quot;Attempt to redefine '%s'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 24</pre></span><pre>           &quot;Syntax error&quot;: &quot;Syntax error: '%s'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 25</pre></span><pre>           &quot;Invalid test condition&quot;: &quot;Invalid test condition: '%s'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 26</pre></span><pre>           &quot;Missing if&quot;: &quot;'elif' or 'else' without matching 'if'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 27</pre></span><pre>           &quot;break outside loop&quot;: &quot;SyntaxError: 'break' outside loop&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 28</pre></span><pre>           },</pre></div>
<div class="cov"><span class="num"><pre> 29</pre></span><pre>    &quot;fr&quot;: {&quot;Unknown command&quot;: &quot;Commande inconnue: %s&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 30</pre></span><pre>           &quot;Indentation error&quot;: &quot;Erreur d'indentation&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 31</pre></span><pre>           &quot;Attempt to redefine&quot;: &quot;Tentative de redéfinir '%s'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 32</pre></span><pre>           &quot;Syntax error&quot;: &quot;Erreur de syntaxe: '%s'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 33</pre></span><pre>           &quot;Invalid test condition&quot;: &quot;Condition non valide: '%s'&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 34</pre></span><pre>           &quot;Missing if&quot;: &quot;'elif' ou 'else' sans le 'if' correspondant&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 35</pre></span><pre>           &quot;break outside loop&quot;: &quot;Erreur de syntaxe: 'break' à l'extérieur d'une boucle&quot;,</pre></div>
<div class="cov"><span class="num"><pre> 36</pre></span><pre>           },</pre></div>
<div class="cov"><span class="num"><pre> 37</pre></span><pre>}</pre></div>
<div class="skip"><span class="num"><pre> 38</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 39</pre></span><pre>comment_pattern = re.compile(&quot;(?!(\'|\&quot;)*#.*(\'|\&quot;)\s*)#.*&quot;)</pre></div>
<div class="skip"><span class="num"><pre> 40</pre></span><pre></pre></div>
<div class="skip"><span class="num"><pre> 41</pre></span><pre># A program can be thought as a series of blocks; each block is composed</pre></div>
<div class="skip"><span class="num"><pre> 42</pre></span><pre># of one or more lines that have the same indentation.</pre></div>
<div class="skip"><span class="num"><pre> 43</pre></span><pre># Each line has a line number, an indentation, and it may have a meaningful</pre></div>
<div class="skip"><span class="num"><pre> 44</pre></span><pre># content and/or contain a comment.</pre></div>
<div class="skip"><span class="num"><pre> 45</pre></span><pre># A comment starts with &quot;#&quot; and includes everything until the end of the line.</pre></div>
<div class="skip"><span class="num"><pre> 46</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 47</pre></span><pre>class LineOfCode(object):</pre></div>
<div class="cov"><span class="num"><pre> 48</pre></span><pre>    '''single line of code in user's program'''</pre></div>
<div class="cov"><span class="num"><pre> 49</pre></span><pre>    def __init__(self, raw_content, line_number):</pre></div>
<div class="cov"><span class="num"><pre> 50</pre></span><pre>        self.line_number = line_number</pre></div>
<div class="cov"><span class="num"><pre> 51</pre></span><pre>        if &quot;#&quot; in raw_content:   # strip comment</pre></div>
<div class="cov"><span class="num"><pre> 52</pre></span><pre>            raw_content = comment_pattern.sub('', raw_content)</pre></div>
<div class="cov"><span class="num"><pre> 53</pre></span><pre>        pattern = re.compile(&quot;( *)(.*)&quot;)</pre></div>
<div class="cov"><span class="num"><pre> 54</pre></span><pre>        match = pattern.search(raw_content)</pre></div>
<div class="cov"><span class="num"><pre> 55</pre></span><pre>        self.indentation = len(match.group(1))</pre></div>
<div class="cov"><span class="num"><pre> 56</pre></span><pre>        self.content = match.group(2)</pre></div>
<div class="skip"><span class="num"><pre> 57</pre></span><pre>        # The following will be initialized by the parser</pre></div>
<div class="cov"><span class="num"><pre> 58</pre></span><pre>        self.name = None</pre></div>
<div class="cov"><span class="num"><pre> 59</pre></span><pre>        self.block = None</pre></div>
<div class="cov"><span class="num"><pre> 60</pre></span><pre>        self.type = None</pre></div>
<div class="cov"><span class="num"><pre> 61</pre></span><pre>        self.condition = None</pre></div>
<div class="skip"><span class="num"><pre> 62</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 63</pre></span><pre>    def __eq__(self, other):</pre></div>
<div class="cov"><span class="num"><pre> 64</pre></span><pre>        '''equality defined to simplify some tests'''</pre></div>
<div class="cov"><span class="num"><pre> 65</pre></span><pre>        return ( (self.line_number == other.line_number) and</pre></div>
<div class="cov"><span class="num"><pre> 66</pre></span><pre>                 (self.indentation == other.indentation) and</pre></div>
<div class="cov"><span class="num"><pre> 67</pre></span><pre>                 (self.content == other.content))</pre></div>
<div class="skip"><span class="num"><pre> 68</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 69</pre></span><pre>class UserProgram(object):</pre></div>
<div class="cov"><span class="num"><pre> 70</pre></span><pre>    def __init__(self, program, language=&quot;en&quot;):</pre></div>
<div class="cov"><span class="num"><pre> 71</pre></span><pre>        lines = program.split(&quot;\n&quot;)</pre></div>
<div class="cov"><span class="num"><pre> 72</pre></span><pre>        self.lines = []</pre></div>
<div class="cov"><span class="num"><pre> 73</pre></span><pre>        self.nb_lines = len(lines)</pre></div>
<div class="cov"><span class="num"><pre> 74</pre></span><pre>        self.language = language</pre></div>
<div class="cov"><span class="num"><pre> 75</pre></span><pre>        self.index = 0</pre></div>
<div class="cov"><span class="num"><pre> 76</pre></span><pre>        for index, line in enumerate(lines):</pre></div>
<div class="cov"><span class="num"><pre> 77</pre></span><pre>            self.lines.append(LineOfCode(line, index))</pre></div>
<div class="cov"><span class="num"><pre> 78</pre></span><pre>        self.builtins = _builtins[language]</pre></div>
<div class="skip"><span class="num"><pre> 79</pre></span><pre>        #</pre></div>
<div class="cov"><span class="num"><pre> 80</pre></span><pre>        self.syntax_error = None</pre></div>
<div class="cov"><span class="num"><pre> 81</pre></span><pre>        self.user_methods = {}</pre></div>
<div class="skip"><span class="num"><pre> 82</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 83</pre></span><pre>    def next_line(self):</pre></div>
<div class="cov"><span class="num"><pre> 84</pre></span><pre>        if self.index &gt;= self.nb_lines:</pre></div>
<div class="cov"><span class="num"><pre> 85</pre></span><pre>            return None</pre></div>
<div class="cov"><span class="num"><pre> 86</pre></span><pre>        self.current_line = self.lines[self.index]</pre></div>
<div class="cov"><span class="num"><pre> 87</pre></span><pre>        self.index += 1</pre></div>
<div class="cov"><span class="num"><pre> 88</pre></span><pre>        return self.current_line</pre></div>
<div class="skip"><span class="num"><pre> 89</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 90</pre></span><pre>    def previous_line(self):</pre></div>
<div class="cov"><span class="num"><pre> 91</pre></span><pre>        self.index -= 1</pre></div>
<div class="skip"><span class="num"><pre> 92</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 93</pre></span><pre>    def abort_parsing(self, msg):</pre></div>
<div class="cov"><span class="num"><pre> 94</pre></span><pre>        self.previous_line()</pre></div>
<div class="cov"><span class="num"><pre> 95</pre></span><pre>        self.syntax_error = [self.index, msg]</pre></div>
<div class="skip"><span class="num"><pre> 96</pre></span><pre></pre></div>
<div class="skip"><span class="num"><pre> 97</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre> 98</pre></span><pre>class Block(object):</pre></div>
<div class="cov"><span class="num"><pre> 99</pre></span><pre>    def __init__(self, program, min_indentation=-1, block_type=None):</pre></div>
<div class="cov"><span class="num"><pre>100</pre></span><pre>        self.lines = []</pre></div>
<div class="cov"><span class="num"><pre>101</pre></span><pre>        self.program = program</pre></div>
<div class="cov"><span class="num"><pre>102</pre></span><pre>        self.min_indentation = min_indentation</pre></div>
<div class="cov"><span class="num"><pre>103</pre></span><pre>        self.block_indentation = None</pre></div>
<div class="cov"><span class="num"><pre>104</pre></span><pre>        self.block_type = block_type</pre></div>
<div class="cov"><span class="num"><pre>105</pre></span><pre>        self.parse()</pre></div>
<div class="skip"><span class="num"><pre>106</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>107</pre></span><pre>    def parse(self):</pre></div>
<div class="cov"><span class="num"><pre>108</pre></span><pre>        previous_line_content = None</pre></div>
<div class="cov"><span class="num"><pre>109</pre></span><pre>        while self.program.syntax_error is None:</pre></div>
<div class="cov"><span class="num"><pre>110</pre></span><pre>            current_line = self.program.next_line()</pre></div>
<div class="cov"><span class="num"><pre>111</pre></span><pre>            if current_line is None:      # end of program</pre></div>
<div class="cov"><span class="num"><pre>112</pre></span><pre>                break</pre></div>
<div class="cov"><span class="num"><pre>113</pre></span><pre>            if not self.handle_indentation(current_line):</pre></div>
<div class="cov"><span class="num"><pre>114</pre></span><pre>                break</pre></div>
<div class="skip"><span class="num"><pre>115</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>116</pre></span><pre>            self.block_indentation = current_line.indentation</pre></div>
<div class="cov"><span class="num"><pre>117</pre></span><pre>            if current_line.content in self.program.builtins:</pre></div>
<div class="cov"><span class="num"><pre>118</pre></span><pre>                current_line.name = self.program.builtins[current_line.content]</pre></div>
<div class="cov"><span class="num"><pre>119</pre></span><pre>                current_line.type = &quot;command&quot;</pre></div>
<div class="cov"><span class="num"><pre>120</pre></span><pre>            elif current_line.content in self.program.user_methods:</pre></div>
<div class="cov"><span class="num"><pre>121</pre></span><pre>                current_line.type = &quot;user method&quot;</pre></div>
<div class="cov"><span class="num"><pre>122</pre></span><pre>                method_def_line = self.program.user_methods[current_line.content]</pre></div>
<div class="cov"><span class="num"><pre>123</pre></span><pre>                current_line.name = method_def_line.method_name</pre></div>
<div class="cov"><span class="num"><pre>124</pre></span><pre>                current_line.block = method_def_line.block</pre></div>
<div class="cov"><span class="num"><pre>125</pre></span><pre>            elif current_line.content.startswith(&quot;def &quot;):</pre></div>
<div class="cov"><span class="num"><pre>126</pre></span><pre>                self.parse_def(current_line)</pre></div>
<div class="cov"><span class="num"><pre>127</pre></span><pre>            elif current_line.content.startswith(&quot;if &quot;):</pre></div>
<div class="cov"><span class="num"><pre>128</pre></span><pre>                self.parse_if(current_line)</pre></div>
<div class="cov"><span class="num"><pre>129</pre></span><pre>            elif current_line.content.startswith(&quot;elif &quot;):</pre></div>
<div class="cov"><span class="num"><pre>130</pre></span><pre>                if (previous_line_content is not None and</pre></div>
<div class="cov"><span class="num"><pre>131</pre></span><pre>                    (previous_line_content.startswith(&quot;if &quot;) or</pre></div>
<div class="cov"><span class="num"><pre>132</pre></span><pre>                     previous_line_content.startswith(&quot;elif &quot;))):</pre></div>
<div class="cov"><span class="num"><pre>133</pre></span><pre>                    self.parse_elif(current_line)</pre></div>
<div class="cov"><span class="num"><pre>134</pre></span><pre>                else:</pre></div>
<div class="cov"><span class="num"><pre>135</pre></span><pre>                    self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>136</pre></span><pre>                                                    ][&quot;Missing if&quot;])</pre></div>
<div class="cov"><span class="num"><pre>137</pre></span><pre>            elif current_line.content.startswith(&quot;else&quot;):</pre></div>
<div class="cov"><span class="num"><pre>138</pre></span><pre>                if (previous_line_content.startswith(&quot;if &quot;) or</pre></div>
<div class="cov"><span class="num"><pre>139</pre></span><pre>                     previous_line_content.startswith(&quot;elif &quot;)):</pre></div>
<div class="cov"><span class="num"><pre>140</pre></span><pre>                    self.parse_else(current_line)</pre></div>
<div class="cov"><span class="num"><pre>141</pre></span><pre>                else:</pre></div>
<div class="cov"><span class="num"><pre>142</pre></span><pre>                    self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>143</pre></span><pre>                                                    ][&quot;Missing if&quot;])</pre></div>
<div class="cov"><span class="num"><pre>144</pre></span><pre>            elif current_line.content.startswith(&quot;while&quot;):</pre></div>
<div class="cov"><span class="num"><pre>145</pre></span><pre>                self.parse_while(current_line)</pre></div>
<div class="cov"><span class="num"><pre>146</pre></span><pre>            elif current_line.content == &quot;break&quot;:</pre></div>
<div class="cov"><span class="num"><pre>147</pre></span><pre>                if self.block_type == &quot;loop&quot;:</pre></div>
<div class="cov"><span class="num"><pre>148</pre></span><pre>                    current_line.type = &quot;break&quot;</pre></div>
<div class="cov"><span class="num"><pre>149</pre></span><pre>                else:</pre></div>
<div class="cov"><span class="num"><pre>150</pre></span><pre>                    self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>151</pre></span><pre>                                                    ][&quot;break outside loop&quot;])</pre></div>
<div class="cov"><span class="num"><pre>152</pre></span><pre>            elif &quot;=&quot; in current_line.content:</pre></div>
<div class="cov"><span class="num"><pre>153</pre></span><pre>                self.parse_assignment(current_line)</pre></div>
<div class="cov"><span class="num"><pre>154</pre></span><pre>            elif not current_line.content: # empty line</pre></div>
<div class="cov"><span class="num"><pre>155</pre></span><pre>                current_line.type = &quot;empty line&quot;</pre></div>
<div class="cov"><span class="num"><pre>156</pre></span><pre>            else:</pre></div>
<div class="cov"><span class="num"><pre>157</pre></span><pre>                self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>158</pre></span><pre>                                                     ][&quot;Unknown command&quot;</pre></div>
<div class="cov"><span class="num"><pre>159</pre></span><pre>                                                       ] % current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>160</pre></span><pre>                break</pre></div>
<div class="cov"><span class="num"><pre>161</pre></span><pre>            self.lines.append(current_line)</pre></div>
<div class="cov"><span class="num"><pre>162</pre></span><pre>            previous_line_content = current_line.content</pre></div>
<div class="skip"><span class="num"><pre>163</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>164</pre></span><pre>    def handle_indentation(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>165</pre></span><pre>        if self.block_indentation is None:   # begin new block</pre></div>
<div class="cov"><span class="num"><pre>166</pre></span><pre>            return self.set_indentation(current_line)</pre></div>
<div class="cov"><span class="num"><pre>167</pre></span><pre>        elif current_line.indentation &lt;= self.min_indentation:  # end block</pre></div>
<div class="cov"><span class="num"><pre>168</pre></span><pre>            self.program.previous_line()</pre></div>
<div class="cov"><span class="num"><pre>169</pre></span><pre>            return False</pre></div>
<div class="cov"><span class="num"><pre>170</pre></span><pre>        elif current_line.indentation != self.block_indentation:</pre></div>
<div class="cov"><span class="num"><pre>171</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>172</pre></span><pre>                                             ][&quot;Indentation error&quot;])</pre></div>
<div class="cov"><span class="num"><pre>173</pre></span><pre>            return False</pre></div>
<div class="cov"><span class="num"><pre>174</pre></span><pre>        return True</pre></div>
<div class="skip"><span class="num"><pre>175</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>176</pre></span><pre>    def set_indentation(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>177</pre></span><pre>        if current_line.indentation &lt;= self.min_indentation:</pre></div>
<div class="cov"><span class="num"><pre>178</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>179</pre></span><pre>                                                 ][&quot;Indentation error&quot;])</pre></div>
<div class="cov"><span class="num"><pre>180</pre></span><pre>            return False</pre></div>
<div class="cov"><span class="num"><pre>181</pre></span><pre>        elif self.min_indentation == -1 and current_line.indentation != 0:</pre></div>
<div class="cov"><span class="num"><pre>182</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>183</pre></span><pre>                                                 ][&quot;Indentation error&quot;])</pre></div>
<div class="cov"><span class="num"><pre>184</pre></span><pre>        else:</pre></div>
<div class="cov"><span class="num"><pre>185</pre></span><pre>            self.block_indentation = current_line.indentation</pre></div>
<div class="cov"><span class="num"><pre>186</pre></span><pre>            return True</pre></div>
<div class="skip"><span class="num"><pre>187</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>188</pre></span><pre>    def parse_def(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>189</pre></span><pre>        current_line.type = &quot;def block&quot;</pre></div>
<div class="cov"><span class="num"><pre>190</pre></span><pre>        pattern = re.compile(&quot;def \s*(.*)\(\)\s*:\s*&quot;)</pre></div>
<div class="cov"><span class="num"><pre>191</pre></span><pre>        match = pattern.search(current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>192</pre></span><pre>        name = match.group(1)</pre></div>
<div class="cov"><span class="num"><pre>193</pre></span><pre>        if (name+&quot;()&quot; in self.program.builtins or</pre></div>
<div class="cov"><span class="num"><pre>194</pre></span><pre>            name+&quot;()&quot; in self.program.user_methods):</pre></div>
<div class="cov"><span class="num"><pre>195</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>196</pre></span><pre>                                                 ][&quot;Attempt to redefine&quot;]% name)</pre></div>
<div class="cov"><span class="num"><pre>197</pre></span><pre>        current_line.method_name = name</pre></div>
<div class="cov"><span class="num"><pre>198</pre></span><pre>        self.program.user_methods[name+&quot;()&quot;] = current_line</pre></div>
<div class="cov"><span class="num"><pre>199</pre></span><pre>        current_line.block = Block(self.program,</pre></div>
<div class="cov"><span class="num"><pre>200</pre></span><pre>                                         min_indentation=current_line.indentation)</pre></div>
<div class="skip"><span class="num"><pre>201</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>202</pre></span><pre>    def parse_if(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>203</pre></span><pre>        current_line.type = &quot;if block&quot;</pre></div>
<div class="cov"><span class="num"><pre>204</pre></span><pre>        pattern = re.compile(&quot;if (.*):\s*&quot;)</pre></div>
<div class="cov"><span class="num"><pre>205</pre></span><pre>        match = pattern.search(current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>206</pre></span><pre>        condition = match.group(1).strip()</pre></div>
<div class="cov"><span class="num"><pre>207</pre></span><pre>        self.parse_if_elif(current_line, condition)</pre></div>
<div class="skip"><span class="num"><pre>208</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>209</pre></span><pre>    def parse_elif(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>210</pre></span><pre>        current_line.type = &quot;elif block&quot;</pre></div>
<div class="cov"><span class="num"><pre>211</pre></span><pre>        pattern = re.compile(&quot;elif (.*):\s*&quot;)</pre></div>
<div class="cov"><span class="num"><pre>212</pre></span><pre>        match = pattern.search(current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>213</pre></span><pre>        condition = match.group(1).strip()</pre></div>
<div class="cov"><span class="num"><pre>214</pre></span><pre>        self.parse_if_elif(current_line, condition)</pre></div>
<div class="skip"><span class="num"><pre>215</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>216</pre></span><pre>    def parse_else(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>217</pre></span><pre>        current_line.type = &quot;else block&quot;</pre></div>
<div class="cov"><span class="num"><pre>218</pre></span><pre>        content = current_line.content.replace(&quot; &quot;, &quot;&quot;)</pre></div>
<div class="cov"><span class="num"><pre>219</pre></span><pre>        if content != &quot;else:&quot;:</pre></div>
<div class="nocov"><span class="num"><pre>220</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="nocov"><span class="num"><pre>221</pre></span><pre>                                                 ][&quot;Syntax error&quot;</pre></div>
<div class="nocov"><span class="num"><pre>222</pre></span><pre>                                                   ]%current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>223</pre></span><pre>        else:</pre></div>
<div class="cov"><span class="num"><pre>224</pre></span><pre>            current_line.block = Block(self.program,</pre></div>
<div class="cov"><span class="num"><pre>225</pre></span><pre>                                    min_indentation=current_line.indentation,</pre></div>
<div class="cov"><span class="num"><pre>226</pre></span><pre>                                    block_type=self.block_type)</pre></div>
<div class="skip"><span class="num"><pre>227</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>228</pre></span><pre>    def parse_if_elif(self, current_line, condition):</pre></div>
<div class="cov"><span class="num"><pre>229</pre></span><pre>        if condition not in _conditions:</pre></div>
<div class="cov"><span class="num"><pre>230</pre></span><pre>            self.program.abort_parsing(</pre></div>
<div class="cov"><span class="num"><pre>231</pre></span><pre>                        _messages[self.program.language][</pre></div>
<div class="cov"><span class="num"><pre>232</pre></span><pre>                                          &quot;Invalid test condition&quot;]% condition)</pre></div>
<div class="cov"><span class="num"><pre>233</pre></span><pre>        else:</pre></div>
<div class="cov"><span class="num"><pre>234</pre></span><pre>            current_line.condition = _conditions[condition]</pre></div>
<div class="cov"><span class="num"><pre>235</pre></span><pre>        current_line.block = Block(self.program,</pre></div>
<div class="cov"><span class="num"><pre>236</pre></span><pre>                                    min_indentation=current_line.indentation,</pre></div>
<div class="cov"><span class="num"><pre>237</pre></span><pre>                                    block_type=self.block_type)</pre></div>
<div class="skip"><span class="num"><pre>238</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>239</pre></span><pre>    def parse_while(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>240</pre></span><pre>        current_line.type = &quot;while block&quot;</pre></div>
<div class="cov"><span class="num"><pre>241</pre></span><pre>        pattern = re.compile(&quot;while (.*):\s*&quot;)</pre></div>
<div class="cov"><span class="num"><pre>242</pre></span><pre>        match = pattern.search(current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>243</pre></span><pre>        condition = match.group(1).strip()</pre></div>
<div class="skip"><span class="num"><pre>244</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>245</pre></span><pre>        if condition == &quot;True&quot;:</pre></div>
<div class="cov"><span class="num"><pre>246</pre></span><pre>            current_line.condition = True</pre></div>
<div class="cov"><span class="num"><pre>247</pre></span><pre>        elif condition in _conditions:</pre></div>
<div class="cov"><span class="num"><pre>248</pre></span><pre>            current_line.condition = _conditions[condition]</pre></div>
<div class="cov"><span class="num"><pre>249</pre></span><pre>        else:</pre></div>
<div class="cov"><span class="num"><pre>250</pre></span><pre>            self.program.abort_parsing(</pre></div>
<div class="cov"><span class="num"><pre>251</pre></span><pre>                        _messages[self.program.language][</pre></div>
<div class="cov"><span class="num"><pre>252</pre></span><pre>                                          &quot;Invalid test condition&quot;]% condition)</pre></div>
<div class="cov"><span class="num"><pre>253</pre></span><pre>        current_line.block = Block(self.program,</pre></div>
<div class="cov"><span class="num"><pre>254</pre></span><pre>                                    min_indentation=current_line.indentation,</pre></div>
<div class="cov"><span class="num"><pre>255</pre></span><pre>                                    block_type=&quot;loop&quot;)</pre></div>
<div class="skip"><span class="num"><pre>256</pre></span><pre></pre></div>
<div class="cov"><span class="num"><pre>257</pre></span><pre>    def parse_assignment(self, current_line):</pre></div>
<div class="cov"><span class="num"><pre>258</pre></span><pre>        '''parses a statement like &quot;a = b&quot; '''</pre></div>
<div class="cov"><span class="num"><pre>259</pre></span><pre>        pattern = re.compile(&quot;^(\w*)\s*=\s*(\w*)\s*$&quot;)</pre></div>
<div class="cov"><span class="num"><pre>260</pre></span><pre>        match = pattern.search(current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>261</pre></span><pre>        if match is None:</pre></div>
<div class="cov"><span class="num"><pre>262</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>263</pre></span><pre>                                                 ][&quot;Syntax error&quot;</pre></div>
<div class="cov"><span class="num"><pre>264</pre></span><pre>                                                   ]%current_line.content)</pre></div>
<div class="cov"><span class="num"><pre>265</pre></span><pre>            return</pre></div>
<div class="cov"><span class="num"><pre>266</pre></span><pre>        left = match.group(1)</pre></div>
<div class="cov"><span class="num"><pre>267</pre></span><pre>        right = match.group(2)</pre></div>
<div class="cov"><span class="num"><pre>268</pre></span><pre>        current_line.type = &quot;assignment&quot;</pre></div>
<div class="cov"><span class="num"><pre>269</pre></span><pre>        if (left+&quot;()&quot; in self.program.builtins  or</pre></div>
<div class="cov"><span class="num"><pre>270</pre></span><pre>            left+&quot;()&quot; in self.program.user_methods):</pre></div>
<div class="cov"><span class="num"><pre>271</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>272</pre></span><pre>                                                 ][&quot;Attempt to redefine&quot;]% left)</pre></div>
<div class="cov"><span class="num"><pre>273</pre></span><pre>        elif right+&quot;()&quot; in self.program.builtins:</pre></div>
<div class="cov"><span class="num"><pre>274</pre></span><pre>            self.program.builtins[left+&quot;()&quot;] = self.program.builtins[right+&quot;()&quot;]</pre></div>
<div class="cov"><span class="num"><pre>275</pre></span><pre>        elif right+&quot;()&quot; in self.program.user_methods:</pre></div>
<div class="cov"><span class="num"><pre>276</pre></span><pre>            self.program.user_methods[left+&quot;()&quot;] = self.program.user_methods[right+&quot;()&quot;]</pre></div>
<div class="cov"><span class="num"><pre>277</pre></span><pre>        else:</pre></div>
<div class="cov"><span class="num"><pre>278</pre></span><pre>            self.program.abort_parsing(_messages[self.program.language</pre></div>
<div class="cov"><span class="num"><pre>279</pre></span><pre>                                                     ][&quot;Unknown command&quot;</pre></div>
<div class="cov"><span class="num"><pre>280</pre></span><pre>                                                       ] % right+&quot;()&quot;)</pre></div>
<div class="skip"><span class="num"><pre>281</pre></span><pre></pre></div>
</div>
</body>
</html>
